

var api = require('./api.js');
var utils = require('../utils/util.js');

/**
 * 网路请求
 */
function request(url, data, successCb, errorCb, completeCb) {
    wx.request({
        url: url,
        method: 'GET',
        data: data,
        success: function(res) {
            utils.isFunction(successCb) && successCb(res.data);
        },
        error: function() {
            utils.isFunction(errorCb) && errorCb();
        },
        complete: function() {
            utils.isFunction(completeCb) && completeCb();
        }
    });
}

/**
 * 新闻列表
 */
function requestNewsList(data, successCb, errorCb, completeCb) {
    request(api.API_NEWS_LIST, data, successCb, errorCb, completeCb);
}

/**
 * 获取新闻详细信息
 */
function requestNewDetail(id, data, successCb, errorCb, completeCb) {
    request(api.API_NEWS_LIST.replace(':id', id), data, successCb, errorCb, completeCb);
}

module.exports = {
  requestNewsList: requestNewsList,
  requestNewDetail: requestNewDetail
}